package edu.tum.cs.stageflow.language.scoping

import org.eclipse.xtext.scoping.IScope
import edu.tum.cs.stageflow.language.stageflow.FlowPoint
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.EcoreUtil2
import edu.tum.cs.stageflow.language.stageflow.Stage
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider

/**
 * This is the internal &quot;single&quot; scope provider that is employed by
 * the other scope providers ({@link StageflowXbaseScopeProvider} and {@link StageflowXbaseBatchScopeProvider})
 * and it uses methods with signature
 * <code>IScope scope_[EClassName]_[EReferenceName](MyType context, EReference ref)</code>
 * to provide scopes.
 */
class StageflowInternalDeclarativeScopeProvider extends AbstractDeclarativeScopeProvider {

	def IScope scope_FlowPoint_port(FlowPoint flowPoint, EReference ref) {
		val sub = flowPoint.sub
		val stage = if (sub == null) {
				EcoreUtil2::getContainerOfType(flowPoint, Stage);
			} else {
				sub.stage;
			}
		if (stage == null) {
			return IScope::NULLSCOPE;
		}
		return Scopes::scopeFor(stage.ports);
	}

}
